package com.snbc.date;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Calendar1 {
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static void main(String[] args) {
        //采用单例模式获取日历对象Calendar.getInstance();
        Calendar c = Calendar.getInstance();
        //Date d = c.getTime();  // 当前日期
        //下个月的倒数第三天d
        //c.setTime(d);
        c.add(Calendar.MONTH, 2);
        c.set(Calendar.DATE, -3);
        System.out.println("下个月的倒数第三天:\t" + format(c.getTime()));
    }

    private static String format(Date time) {
        return sdf.format(time);
    }
}
